package priv.pront.code.lanqiao.competition.course.date0403;

import java.util.Scanner;

public class 最大连续子段和 {
    static int n,sum = 0,max = 0;
    static int[] arr;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (sum > 0) {
                sum += arr[i];
            }else{
                sum = arr[i];
            }
            if (max < sum) {
                max = sum;
            }
        }
        System.out.println(max);
    }
}
